package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcOrdexecEntity;
import com.dhcc.cdc.busi.service.ICdcOrdexecService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 医嘱执行记录
 * 
 * @ClassName: CdcOrdexecController
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:07
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/cdcordexec")
public class CdcOrdexecController extends BaseController {

	private String PREFIX = "/backend/cdc/cdcordexec/";

	@Autowired
	private ICdcOrdexecService cdcOrdexecService;
	

    /**
     * 跳转到医嘱执行记录列表首页
     */
    @RequestMapping("")
    @Permission("cdcordexec:list")
    public String index() {
        return PREFIX + "cdcordexec.html";
    }
	
    /**
     * 跳转到新增医嘱执行记录
     */
    @RequestMapping("/to_add")
    @Permission("cdcordexec:add")
    public String toAdd() {
        return PREFIX + "cdcordexec_add.html";
    }
	
	/**
     * 跳转到修改医嘱执行记录
     */
    @RequestMapping("/to_update/{cdcOrdexecId}")
    @Permission("cdcordexec:update")
    public String toUpdate(@PathVariable Long cdcOrdexecId, Model model) {
        CdcOrdexecEntity cdcOrdexec = this.cdcOrdexecService.selectById(cdcOrdexecId);
        model.addAttribute("cdcOrdexec",cdcOrdexec);
        return PREFIX + "cdcordexec_edit.html";
    }

    /**
     * 获取医嘱执行记录列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("cdcordexec:list")
    public Object list(@RequestParam Map<String, Object> params) {
        List<CdcOrdexecEntity> result = null;
        Page<CdcOrdexecEntity> page = new PageFactory<CdcOrdexecEntity>().defaultPage();
        if((CommonUtil.isNotEmpty(params.get("NotQuery")))&&(params.get("NotQuery").toString().equals("true"))){
            result = new ArrayList<CdcOrdexecEntity>();
        }else{
            result = this.cdcOrdexecService.page(page,params);
        }
        page.setRecords((List<CdcOrdexecEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增医嘱执行记录
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("cdcordexec:add")
    @BussinessLog(value = "新增医嘱执行记录")
    public Object add(CdcOrdexecEntity cdcOrdexec) {
        if (CommonUtil.isOneEmpty(cdcOrdexec)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        cdcOrdexec.insert();
        return R.ok();
    }

    /**
     * 删除医嘱执行记录
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("cdcordexec:delete")
    @BussinessLog(value = "删除医嘱执行记录")
    public Object delete(@RequestParam Long cdcOrdexecId) {
	
        this.cdcOrdexecService.deleteById(cdcOrdexecId);

        return R.ok();
    }

    /**
     * 修改医嘱执行记录
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("cdcordexec:update")
    @BussinessLog(value = "修改医嘱执行记录")
    public Object update(CdcOrdexecEntity cdcOrdexec) {
        if (CommonUtil.isOneEmpty(cdcOrdexec)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcOrdexecEntity old = this.cdcOrdexecService.selectById(cdcOrdexec.getId());

        old.setXcode(cdcOrdexec.getXcode());
        old.setEpisodeId(cdcOrdexec.getEpisodeId());
        old.setOrderMastId(cdcOrdexec.getOrderMastId());
        old.setBusOrderStatusId(cdcOrdexec.getBusOrderStatusId());
        old.setOrderDate(cdcOrdexec.getOrderDate());
        old.setOrderLocId(cdcOrdexec.getOrderLocId());
        old.setRecLocId(cdcOrdexec.getRecLocId());
        old.setStartDate(cdcOrdexec.getStartDate());
        old.setEndDate(cdcOrdexec.getEndDate());
        old.setBusOrderInstrucId(cdcOrdexec.getBusOrderInstrucId());
        old.setDoseQty(cdcOrdexec.getDoseQty());
        old.setBusOrderUnitId(cdcOrdexec.getBusOrderUnitId());
        old.setBusOrderFreqId(cdcOrdexec.getBusOrderFreqId());
        old.setDataId(cdcOrdexec.getDataId());
        old.setIsActive(cdcOrdexec.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
